Skip to content

fix: preserve TOML decorations/comments across set mutations - #12

Merged
rainbowatcher merged 8 commits into
mainfrom
11-comment-gets-duplicated
Feb 9, 2026
Merged

fix: preserve TOML decorations/comments across set mutations#12
rainbowatcher merged 8 commits into
mainfrom
11-comment-gets-duplicated

Conversation

@rainbowatcher

Copy link
Copy Markdown
Owner

Summary

  • refactor set-path mutation flow for arrays, tables, and array-of-tables
  • preserve value/key decorations and inline comments during set/insert/remove operations
  • fix array deletion formatting when shrinking to a single element (keep inline vs multiline style)
  • add/expand Rust unit tests and JS regression tests for decoration/formatting behavior
  • include supporting docs/CI/lint/deps updates included in this branch

Validation

  • cargo test --lib
  • pnpm build
  • pnpm test -- --run tests/array_edit.test.ts tests/edit.test.ts

Notes

  • This PR is based on branch 11-comment-gets-duplicated and includes all commits currently ahead of main on that branch.

- Import Array from toml_edit to enable array editing support
- Refactor set_value to route path mutations through array index handling or table-like handling
- Introduce helper handle_array_path to manage insert, replace, or remove for array items
- Introduce helper handle_tablelike_path to manage table-like mutations with inline table awareness
- Add insert_into_value_array to centralize insertion logic for ordinary arrays and handle value decoration
- Add insert_into_aot to handle insertion into arrays of tables with proper type checks
- Implement index bounds checks that return precise errors including the parent path
- Add remove_existing_array_item and remove_array_item_and_fix_format to cleanly remove items and fix formatting
- Add preserve_existing_value_decor to keep original decorations when replacing existing values
- Extend insert_tablelike logic to properly handle existing keys, inline tables, and associated decorations
- Add remove_inline_table_key_and_clean_comments to safely remove a key from an inline table and normalize remaining keys
- Refactor update_existing_tablelike_key and related code to manage inline table cleanup and key decoration consistently

Signed-off-by: rainbowatcher <rainbow-w@qq.com>
@rainbowatcher rainbowatcher linked an issue Feb 9, 2026 that may be closed by this pull request
@rainbowatcher
rainbowatcher merged commit e8f4197 into main Feb 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Comment gets duplicated

1 participant